package GUI;

import GUI.VendasPanel;
import javax.swing.JPanel;
import org.pebom.util.Diversos;

public class MainWindow extends javax.swing.JFrame {

    private static final long serialVersionUID = 3013273981714143582L;
    private static MainWindow instance = null;


    private MainWindow() throws Exception {
        initComponents();
        /**Dimensão da tela*/
        setSize(800, 600);
        /**Centraliza este JFrame*/
        Diversos.centralizaContainer(this);
        Diversos.getInstance().setMain(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jxcpMenu = new org.jdesktop.swingx.JXCollapsiblePane();
        imgPP = new javax.swing.JLabel();
        jxtpMenu = new org.jdesktop.swingx.JXTaskPane();
        btnCadastrarPreco = new javax.swing.JButton();
        jpMain = new javax.swing.JPanel();
        imgPrecoPublico = new javax.swing.JLabel();

        setTitle("PeBom");

        jxcpMenu.setBackground(new java.awt.Color(255, 255, 255));
        jxcpMenu.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        imgPP.setBackground(new java.awt.Color(254, 254, 254));
        imgPP.setForeground(new java.awt.Color(254, 254, 254));
        imgPP.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        imgPP.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/pebom/empresa/logoMin.gif"))); // NOI18N
        imgPP.setLabelFor(jpMain);
        jxcpMenu.getContentPane().add(imgPP);

        jxtpMenu.setTitle("Operações");
        jxtpMenu.setFont(new java.awt.Font("Verdana", 1, 11));

        btnCadastrarPreco.setFont(new java.awt.Font("Verdana", 0, 11));
        btnCadastrarPreco.setText("Vendas");
        btnCadastrarPreco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCadastrarPrecoActionPerformed(evt);
            }
        });
        jxtpMenu.getContentPane().add(btnCadastrarPreco);

        jxcpMenu.getContentPane().add(jxtpMenu);

        getContentPane().add(jxcpMenu, java.awt.BorderLayout.LINE_START);

        jpMain.setBackground(new java.awt.Color(255, 255, 255));
        jpMain.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "PeBom", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Verdana", 0, 11))); // NOI18N

        imgPrecoPublico.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/pebom/empresa/logo.gif"))); // NOI18N
        imgPrecoPublico.setLabelFor(jpMain);

        org.jdesktop.layout.GroupLayout jpMainLayout = new org.jdesktop.layout.GroupLayout(jpMain);
        jpMain.setLayout(jpMainLayout);
        jpMainLayout.setHorizontalGroup(
            jpMainLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jpMainLayout.createSequentialGroup()
                .add(182, 182, 182)
                .add(imgPrecoPublico)
                .addContainerGap(199, Short.MAX_VALUE))
        );
        jpMainLayout.setVerticalGroup(
            jpMainLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jpMainLayout.createSequentialGroup()
                .add(45, 45, 45)
                .add(imgPrecoPublico)
                .addContainerGap(360, Short.MAX_VALUE))
        );

        getContentPane().add(jpMain, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCadastrarPrecoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCadastrarPrecoActionPerformed
        //showPanel(new ListarCadastrar());
        showPanel(new VendasPanel());
}//GEN-LAST:event_btnCadastrarPrecoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCadastrarPreco;
    private javax.swing.JLabel imgPP;
    private javax.swing.JLabel imgPrecoPublico;
    private javax.swing.JPanel jpMain;
    private org.jdesktop.swingx.JXCollapsiblePane jxcpMenu;
    private org.jdesktop.swingx.JXTaskPane jxtpMenu;
    // End of variables declaration//GEN-END:variables

    public static MainWindow getInstance() throws Exception {
        if (instance == null) {
            instance = new MainWindow();
        }
        return instance;
    }

    public static void zeraInstancia() {
        instance = null;
    }

    /**Funcao responsavel por abrir o panel*/
    public void showPanel(JPanel panel) {
        getContentPane().remove(1);
        /**Adiciona o panel no centro*/
        getContentPane().add(panel, java.awt.BorderLayout.CENTER);

        pack();
        validate();
        update(this.getGraphics());
    }
    
    public static void main(String args[]) throws Exception {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
         
                    new MainWindow().setVisible(true);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
    }
    
}
